package com.maila.xiaoaoschool.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.cjj.MaterialRefreshLayout;
import com.google.gson.Gson;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.adapter.SaleFoodAdapter;
import com.maila.xiaoaoschool.api.PrefApi;
import com.maila.xiaoaoschool.entity.SaleGoods;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by mark on 2017/12/26.
 */

class SaleDetailActivity extends AppCompatActivity {
    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.tv_shop_namee)
    TextView tvShopNamee;
    @BindView(R.id.lv_fujin)
    ListView lvFujin;
    @BindView(R.id.hot_refresh)
    MaterialRefreshLayout hotRefresh;
    SaleFoodAdapter saleFoodAdapter;
    private String adcode="1";
    private int page=1;
    private int size=8;
    Gson gson=new Gson();
    int type;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sale_details);
        ButterKnife.bind(this);
        type=getIntent().getIntExtra("OPT",-1);
        saleFoodAdapter=new SaleFoodAdapter(this);
        lvFujin.setAdapter(saleFoodAdapter);
        initdata();
    }

    private void initdata() {
        new PrefApi(this, new VolleyInterface() {
            @Override
            public void onSuccess(String result) {
                SaleGoods saleGoods=gson.fromJson(result,SaleGoods.class);
                if(saleGoods.getResult()==1){
                    if(page==1){
                        saleFoodAdapter.setMdata(saleGoods.getData());
                    }else {
                        saleFoodAdapter.addMdata(saleGoods.getData());
                    }

                }else {
                    Toast.makeText(SaleDetailActivity.this, ""+saleGoods.getMessage(), Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onError(VolleyError error) {

            }
        }).getSalelistBytype(type,adcode,page,size);
    }

    @OnClick(R.id.white_return_iv)
    public void onViewClicked() {
        finish();
    }
}
